﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:monthSupplayPlan
	/// </summary>
	public partial class monthSupplayPlan
	{
		public monthSupplayPlan()
		{}
        /// <summary>
        /// 获取已生成月供应计划
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListMonthSupplyTotalCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VmonthSupplyPlanTotalCount where ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public bool UpdatearrivalAddress(string  add, string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("arrivalAddress=@arrivalAddress ");
            strSql.Append(" where monthSupplyPlanId in(" + ids + ")");
            SqlParameter[] parameters = {					
					new SqlParameter("@arrivalAddress", SqlDbType.VarChar,50)
					};
            parameters[0].Value = add;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool UpdatearrivalAddresshs(string add, string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update recovery_scrap_material  set ");
            strSql.Append("arrivalAddress=@arrivalAddress ");
            strSql.Append(" where rsmid in(" + ids + ")");
            SqlParameter[] parameters = {
                    new SqlParameter("@arrivalAddress", SqlDbType.VarChar,50)
                    };
            parameters[0].Value = add;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 获取月供应计划内容列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListMonthSupplyInfo(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VmonthSupplyPlaneInfo where ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 更新当月计划状态
        /// </summary>
        /// <param name="ks"></param>
        /// <param name="js"></param>
        /// <returns></returns>
        public bool Updatedatestatus()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("status= '0' ");
            strSql.Append(" where status = '1'");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 获取数据列表，包含当月计划的配送入库量(innums)
        /// 注意出现"null"值现象
        /// </summary>
        public DataSet GetListInnums(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VmonthSupplyInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        public bool Updateskd(string ids, string skstate, DateTime d)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("goodsQualityStatus=@goodsQualityStatus, ");
            strSql.Append("goodsQualityStatusDate=@goodsQualityStatusDate ");
            strSql.Append(" where monthSupplyPlanId in(" + ids + ")");
            SqlParameter[] parameters = {
					new SqlParameter("@goodsQualityStatus", SqlDbType.VarChar,10),
					new SqlParameter("@goodsQualityStatusDate", SqlDbType.DateTime)
					
					};
            parameters[0].Value = skstate;
            parameters[1].Value = d;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public DataSet GetListnums(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select projectName, proid, material, thisMonthCount, nums,synum, monthSupplyPlanId,sname,user_name,isGoodsQualityStatus,goodsQualityStatus,arrivalAddress,linkman, contactWay,result,supplyDate,equipmentManage,winbid,ssum,remark ");
            strSql.Append(" FROM Vmonthdislist where 1=1");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListnumshs(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select rsmid, projectName, proid, material, nums,suppliername, arrivalAddress ,mrsmidcn");
            strSql.Append(" FROM Vrecovery where 1=1");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListlink(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select supplyDate,purchaseid,projectName, proid, material, thisMonthCount, sname,arrivalAddress,linkman, contactWay,user_id ");
            strSql.Append(" FROM Vmonthlink where 1=1");
            if (strWhere.Trim() != "")
            {
                strSql.Append(strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public bool Updatedate(int type, int did)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            if (type == 0)
                strSql.Append("lastArrivalDate=GETDATE() ");
            if (type == 1)
                strSql.Append("lastCheckedDate=GETDATE() ");
            if (type == 2)
                strSql.Append("lastInstoreDate=GETDATE() ");
            strSql.Append(" where monthSupplyPlanId in( select gid from distribution where did=" + did + ")");

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool deldate(int type, int did)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            if (type == 0)
                strSql.Append("lastArrivalDate=NULL ");
            if (type == 1)
                strSql.Append("lastCheckedDate=NULL ");
            if (type == 2)
                strSql.Append("lastInstoreDate=NULL ");
            strSql.Append(" where monthSupplyPlanId in( select gid from distribution where did=" + did + ")");

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Updateresult(int did)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("result=(select case when thisMonthCount=innums then '已完成' else '计划数：'+ convert(varchar(20),thisMonthCount)+'已入库：'+convert(varchar(20),innums) end as result from ");
            strSql.Append(" [Vmonthallnums] where monthSupplyPlanId in( select gid from distribution where did=" + did + "))");
            strSql.Append(" where monthSupplyPlanId in( select gid from distribution where did=" + did + ")");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Updateuid(int uid, string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("user_id=@user_id ");
            strSql.Append(" where monthSupplyPlanId in(" + ids + ")");
            SqlParameter[] parameters = {					
					new SqlParameter("@user_id", SqlDbType.Int,4)
					};
            parameters[0].Value = uid;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool Updateuid(string ids)
        {
            //if (!checkdis(ids))
            //{
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update monthSupplayPlan set ");
                strSql.Append("user_id=@user_id ");
                strSql.Append(" where monthSupplyPlanId in(" + ids + ")");
                SqlParameter[] parameters = {					
					new SqlParameter("@user_id", SqlDbType.Int,4)
					};
                parameters[0].Value = DBNull.Value;
                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            //}
            //else
            //    return false;
        }
        public bool checkdis(string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from distribution ");            
            strSql.Append(" where gid in(" + ids + ")");            
            int rows =int.Parse(DbHelperSQL.GetSingle(strSql.ToString()).ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("monthSupplyPlanId", "monthSupplayPlan");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int monthSupplyPlanId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from monthSupplayPlan");
            strSql.Append(" where monthSupplyPlanId=@monthSupplyPlanId");
            SqlParameter[] parameters = {
					new SqlParameter("@monthSupplyPlanId", SqlDbType.Int,4)
			};
            parameters[0].Value = monthSupplyPlanId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.monthSupplayPlan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into monthSupplayPlan(");
            strSql.Append("supplyDate,supplyPlanId,thisMonthCount,goodsQualityStatus,isGoodsQualityStatus,goodsQualityStatusDate,sendStatus,sendStatusDate,lastArrivalDate,fristCheckedCount,lastCheckedDate,instoreCount,lastInstoreDate,result,arrivalAddress,linkman,contactWay,user_id,status,arrivalGoodsBillStatus,arrivalGoodsBillTime,isUpErp,equipmentManage,createTime)");
            strSql.Append(" values (");
            strSql.Append("@supplyDate,@supplyPlanId,@thisMonthCount,@goodsQualityStatus,@isGoodsQualityStatus,@goodsQualityStatusDate,@sendStatus,@sendStatusDate,@lastArrivalDate,@fristCheckedCount,@lastCheckedDate,@instoreCount,@lastInstoreDate,@result,@arrivalAddress,@linkman,@contactWay,@user_id,@status,@arrivalGoodsBillStatus,@arrivalGoodsBillTime,@isUpErp,@equipmentManage,@createTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@supplyDate", SqlDbType.DateTime),
					new SqlParameter("@supplyPlanId", SqlDbType.Int,4),
					new SqlParameter("@thisMonthCount", SqlDbType.Decimal,9),
					new SqlParameter("@goodsQualityStatus", SqlDbType.VarChar,10),
					new SqlParameter("@isGoodsQualityStatus", SqlDbType.Bit,1),
					new SqlParameter("@goodsQualityStatusDate", SqlDbType.DateTime),
					new SqlParameter("@sendStatus", SqlDbType.VarChar,10),
					new SqlParameter("@sendStatusDate", SqlDbType.DateTime),
					new SqlParameter("@lastArrivalDate", SqlDbType.DateTime),
					new SqlParameter("@fristCheckedCount", SqlDbType.Decimal,9),
					new SqlParameter("@lastCheckedDate", SqlDbType.DateTime),
					new SqlParameter("@instoreCount", SqlDbType.Decimal,9),
					new SqlParameter("@lastInstoreDate", SqlDbType.DateTime),
					new SqlParameter("@result", SqlDbType.VarChar,100),
					new SqlParameter("@arrivalAddress", SqlDbType.VarChar,50),
					new SqlParameter("@linkman", SqlDbType.NVarChar,20),
					new SqlParameter("@contactWay", SqlDbType.VarChar,100),
					new SqlParameter("@user_id", SqlDbType.Int,4),
					new SqlParameter("@status", SqlDbType.VarChar,10),
					new SqlParameter("@arrivalGoodsBillStatus", SqlDbType.VarChar,50),
					new SqlParameter("@arrivalGoodsBillTime", SqlDbType.DateTime),
					new SqlParameter("@isUpErp", SqlDbType.Bit,1),
					new SqlParameter("@equipmentManage", SqlDbType.NVarChar,100),
					new SqlParameter("@createTime", SqlDbType.DateTime)};
            parameters[0].Value = model.supplyDate;
            parameters[1].Value = model.supplyPlanId;
            parameters[2].Value = model.thisMonthCount;
            parameters[3].Value = model.goodsQualityStatus;
            parameters[4].Value = model.isGoodsQualityStatus;
            parameters[5].Value = model.goodsQualityStatusDate;
            parameters[6].Value = model.sendStatus;
            parameters[7].Value = model.sendStatusDate;
            parameters[8].Value = model.lastArrivalDate;
            parameters[9].Value = model.fristCheckedCount;
            parameters[10].Value = model.lastCheckedDate;
            parameters[11].Value = model.instoreCount;
            parameters[12].Value = model.lastInstoreDate;
            parameters[13].Value = model.result;
            parameters[14].Value = model.arrivalAddress;
            parameters[15].Value = model.linkman;
            parameters[16].Value = model.contactWay;
            parameters[17].Value = model.user_id;
            parameters[18].Value = model.status;
            parameters[19].Value = model.arrivalGoodsBillStatus;
            parameters[20].Value = model.arrivalGoodsBillTime;
            parameters[21].Value = model.isUpErp;
            parameters[22].Value = model.equipmentManage;
            parameters[23].Value = model.createTime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.monthSupplayPlan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update monthSupplayPlan set ");
            strSql.Append("supplyDate=@supplyDate,");
            strSql.Append("supplyPlanId=@supplyPlanId,");
            strSql.Append("thisMonthCount=@thisMonthCount,");
            strSql.Append("goodsQualityStatus=@goodsQualityStatus,");
            strSql.Append("isGoodsQualityStatus=@isGoodsQualityStatus,");
            strSql.Append("goodsQualityStatusDate=@goodsQualityStatusDate,");
            strSql.Append("sendStatus=@sendStatus,");
            strSql.Append("sendStatusDate=@sendStatusDate,");
            strSql.Append("lastArrivalDate=@lastArrivalDate,");
            strSql.Append("fristCheckedCount=@fristCheckedCount,");
            strSql.Append("lastCheckedDate=@lastCheckedDate,");
            strSql.Append("instoreCount=@instoreCount,");
            strSql.Append("lastInstoreDate=@lastInstoreDate,");
            strSql.Append("result=@result,");
            strSql.Append("arrivalAddress=@arrivalAddress,");
            strSql.Append("linkman=@linkman,");
            strSql.Append("contactWay=@contactWay,");
            strSql.Append("user_id=@user_id,");
            strSql.Append("status=@status,");
            strSql.Append("arrivalGoodsBillStatus=@arrivalGoodsBillStatus,");
            strSql.Append("arrivalGoodsBillTime=@arrivalGoodsBillTime,");
            strSql.Append("isUpErp=@isUpErp,");
            strSql.Append("equipmentManage=@equipmentManage,");
            strSql.Append("createTime=@createTime");
            strSql.Append(" where monthSupplyPlanId=@monthSupplyPlanId");
            SqlParameter[] parameters = {
					new SqlParameter("@supplyDate", SqlDbType.DateTime),
					new SqlParameter("@supplyPlanId", SqlDbType.Int,4),
					new SqlParameter("@thisMonthCount", SqlDbType.Decimal,9),
					new SqlParameter("@goodsQualityStatus", SqlDbType.VarChar,10),
					new SqlParameter("@isGoodsQualityStatus", SqlDbType.Bit,1),
					new SqlParameter("@goodsQualityStatusDate", SqlDbType.DateTime),
					new SqlParameter("@sendStatus", SqlDbType.VarChar,10),
					new SqlParameter("@sendStatusDate", SqlDbType.DateTime),
					new SqlParameter("@lastArrivalDate", SqlDbType.DateTime),
					new SqlParameter("@fristCheckedCount", SqlDbType.Decimal,9),
					new SqlParameter("@lastCheckedDate", SqlDbType.DateTime),
					new SqlParameter("@instoreCount", SqlDbType.Decimal,9),
					new SqlParameter("@lastInstoreDate", SqlDbType.DateTime),
					new SqlParameter("@result", SqlDbType.VarChar,100),
					new SqlParameter("@arrivalAddress", SqlDbType.VarChar,50),
					new SqlParameter("@linkman", SqlDbType.NVarChar,20),
					new SqlParameter("@contactWay", SqlDbType.VarChar,100),
					new SqlParameter("@user_id", SqlDbType.Int,4),
					new SqlParameter("@status", SqlDbType.VarChar,10),
					new SqlParameter("@arrivalGoodsBillStatus", SqlDbType.VarChar,50),
					new SqlParameter("@arrivalGoodsBillTime", SqlDbType.DateTime),
					new SqlParameter("@isUpErp", SqlDbType.Bit,1),
					new SqlParameter("@equipmentManage", SqlDbType.NVarChar,100),
					new SqlParameter("@createTime", SqlDbType.DateTime),
					new SqlParameter("@monthSupplyPlanId", SqlDbType.Int,4)};
            parameters[0].Value = model.supplyDate;
            parameters[1].Value = model.supplyPlanId;
            parameters[2].Value = model.thisMonthCount;
            parameters[3].Value = model.goodsQualityStatus;
            parameters[4].Value = model.isGoodsQualityStatus;
            parameters[5].Value = model.goodsQualityStatusDate;
            parameters[6].Value = model.sendStatus;
            parameters[7].Value = model.sendStatusDate;
            parameters[8].Value = model.lastArrivalDate;
            parameters[9].Value = model.fristCheckedCount;
            parameters[10].Value = model.lastCheckedDate;
            parameters[11].Value = model.instoreCount;
            parameters[12].Value = model.lastInstoreDate;
            parameters[13].Value = model.result;
            parameters[14].Value = model.arrivalAddress;
            parameters[15].Value = model.linkman;
            parameters[16].Value = model.contactWay;
            parameters[17].Value = model.user_id;
            parameters[18].Value = model.status;
            parameters[19].Value = model.arrivalGoodsBillStatus;
            parameters[20].Value = model.arrivalGoodsBillTime;
            parameters[21].Value = model.isUpErp;
            parameters[22].Value = model.equipmentManage;
            parameters[23].Value = model.createTime;
            parameters[24].Value = model.monthSupplyPlanId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int monthSupplyPlanId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from monthSupplayPlan ");
            strSql.Append(" where monthSupplyPlanId=@monthSupplyPlanId");
            SqlParameter[] parameters = {
					new SqlParameter("@monthSupplyPlanId", SqlDbType.Int,4)
			};
            parameters[0].Value = monthSupplyPlanId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string monthSupplyPlanIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from monthSupplayPlan ");
            strSql.Append(" where monthSupplyPlanId in (" + monthSupplyPlanIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.monthSupplayPlan GetModel(int monthSupplyPlanId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 monthSupplyPlanId,supplyDate,supplyPlanId,thisMonthCount,goodsQualityStatus,isGoodsQualityStatus,goodsQualityStatusDate,sendStatus,sendStatusDate,lastArrivalDate,fristCheckedCount,lastCheckedDate,instoreCount,lastInstoreDate,result,arrivalAddress,linkman,contactWay,user_id,status,arrivalGoodsBillStatus,arrivalGoodsBillTime,isUpErp,equipmentManage,createTime from monthSupplayPlan ");
            strSql.Append(" where monthSupplyPlanId=@monthSupplyPlanId");
            SqlParameter[] parameters = {
					new SqlParameter("@monthSupplyPlanId", SqlDbType.Int,4)
			};
            parameters[0].Value = monthSupplyPlanId;

            Maticsoft.Model.monthSupplayPlan model = new Maticsoft.Model.monthSupplayPlan();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["monthSupplyPlanId"] != null && ds.Tables[0].Rows[0]["monthSupplyPlanId"].ToString() != "")
                {
                    model.monthSupplyPlanId = int.Parse(ds.Tables[0].Rows[0]["monthSupplyPlanId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["supplyDate"] != null && ds.Tables[0].Rows[0]["supplyDate"].ToString() != "")
                {
                    model.supplyDate = DateTime.Parse(ds.Tables[0].Rows[0]["supplyDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["supplyPlanId"] != null && ds.Tables[0].Rows[0]["supplyPlanId"].ToString() != "")
                {
                    model.supplyPlanId = int.Parse(ds.Tables[0].Rows[0]["supplyPlanId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["thisMonthCount"] != null && ds.Tables[0].Rows[0]["thisMonthCount"].ToString() != "")
                {
                    model.thisMonthCount = decimal.Parse(ds.Tables[0].Rows[0]["thisMonthCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["goodsQualityStatus"] != null && ds.Tables[0].Rows[0]["goodsQualityStatus"].ToString() != "")
                {
                    model.goodsQualityStatus = ds.Tables[0].Rows[0]["goodsQualityStatus"].ToString();
                }
                if (ds.Tables[0].Rows[0]["isGoodsQualityStatus"] != null && ds.Tables[0].Rows[0]["isGoodsQualityStatus"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["isGoodsQualityStatus"].ToString() == "1") || (ds.Tables[0].Rows[0]["isGoodsQualityStatus"].ToString().ToLower() == "true"))
                    {
                        model.isGoodsQualityStatus = true;
                    }
                    else
                    {
                        model.isGoodsQualityStatus = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["goodsQualityStatusDate"] != null && ds.Tables[0].Rows[0]["goodsQualityStatusDate"].ToString() != "")
                {
                    model.goodsQualityStatusDate = DateTime.Parse(ds.Tables[0].Rows[0]["goodsQualityStatusDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sendStatus"] != null && ds.Tables[0].Rows[0]["sendStatus"].ToString() != "")
                {
                    model.sendStatus = ds.Tables[0].Rows[0]["sendStatus"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sendStatusDate"] != null && ds.Tables[0].Rows[0]["sendStatusDate"].ToString() != "")
                {
                    model.sendStatusDate = DateTime.Parse(ds.Tables[0].Rows[0]["sendStatusDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastArrivalDate"] != null && ds.Tables[0].Rows[0]["lastArrivalDate"].ToString() != "")
                {
                    model.lastArrivalDate = DateTime.Parse(ds.Tables[0].Rows[0]["lastArrivalDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["fristCheckedCount"] != null && ds.Tables[0].Rows[0]["fristCheckedCount"].ToString() != "")
                {
                    model.fristCheckedCount = decimal.Parse(ds.Tables[0].Rows[0]["fristCheckedCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastCheckedDate"] != null && ds.Tables[0].Rows[0]["lastCheckedDate"].ToString() != "")
                {
                    model.lastCheckedDate = DateTime.Parse(ds.Tables[0].Rows[0]["lastCheckedDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["instoreCount"] != null && ds.Tables[0].Rows[0]["instoreCount"].ToString() != "")
                {
                    model.instoreCount = decimal.Parse(ds.Tables[0].Rows[0]["instoreCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastInstoreDate"] != null && ds.Tables[0].Rows[0]["lastInstoreDate"].ToString() != "")
                {
                    model.lastInstoreDate = DateTime.Parse(ds.Tables[0].Rows[0]["lastInstoreDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["result"] != null && ds.Tables[0].Rows[0]["result"].ToString() != "")
                {
                    model.result = ds.Tables[0].Rows[0]["result"].ToString();
                }
                if (ds.Tables[0].Rows[0]["arrivalAddress"] != null && ds.Tables[0].Rows[0]["arrivalAddress"].ToString() != "")
                {
                    model.arrivalAddress = ds.Tables[0].Rows[0]["arrivalAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["linkman"] != null && ds.Tables[0].Rows[0]["linkman"].ToString() != "")
                {
                    model.linkman = ds.Tables[0].Rows[0]["linkman"].ToString();
                }
                if (ds.Tables[0].Rows[0]["contactWay"] != null && ds.Tables[0].Rows[0]["contactWay"].ToString() != "")
                {
                    model.contactWay = ds.Tables[0].Rows[0]["contactWay"].ToString();
                }
                if (ds.Tables[0].Rows[0]["user_id"] != null && ds.Tables[0].Rows[0]["user_id"].ToString() != "")
                {
                    model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = ds.Tables[0].Rows[0]["status"].ToString();
                }
                if (ds.Tables[0].Rows[0]["arrivalGoodsBillStatus"] != null && ds.Tables[0].Rows[0]["arrivalGoodsBillStatus"].ToString() != "")
                {
                    model.arrivalGoodsBillStatus = ds.Tables[0].Rows[0]["arrivalGoodsBillStatus"].ToString();
                }
                if (ds.Tables[0].Rows[0]["arrivalGoodsBillTime"] != null && ds.Tables[0].Rows[0]["arrivalGoodsBillTime"].ToString() != "")
                {
                    model.arrivalGoodsBillTime = DateTime.Parse(ds.Tables[0].Rows[0]["arrivalGoodsBillTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["isUpErp"] != null && ds.Tables[0].Rows[0]["isUpErp"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["isUpErp"].ToString() == "1") || (ds.Tables[0].Rows[0]["isUpErp"].ToString().ToLower() == "true"))
                    {
                        model.isUpErp = true;
                    }
                    else
                    {
                        model.isUpErp = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["equipmentManage"] != null && ds.Tables[0].Rows[0]["equipmentManage"].ToString() != "")
                {
                    model.equipmentManage = ds.Tables[0].Rows[0]["equipmentManage"].ToString();
                }
                if (ds.Tables[0].Rows[0]["createTime"] != null && ds.Tables[0].Rows[0]["createTime"].ToString() != "")
                {
                    model.createTime = DateTime.Parse(ds.Tables[0].Rows[0]["createTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" monthSupplyPlanId,supplyDate,supplyPlanId,thisMonthCount,goodsQualityStatus,isGoodsQualityStatus,goodsQualityStatusDate,sendStatus,sendStatusDate,lastArrivalDate,fristCheckedCount,lastCheckedDate,instoreCount,lastInstoreDate,result,arrivalAddress,linkman,contactWay,user_id,status,arrivalGoodsBillStatus,arrivalGoodsBillTime,isUpErp,equipmentManage,createTime ");
            strSql.Append(" FROM monthSupplayPlan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [VmonthSupplyInfo] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT top 7 * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.monthSupplyPlanId desc");
            }
            strSql.Append(")AS Row, T.*  from [VmonthSupplyInfo] T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "monthSupplayPlan";
            parameters[1].Value = "monthSupplyPlanId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method

        

		

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VmonthSupplyInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
	}
}

